package com.erp.auto.controller;

import com.erp.auto.domain.ErpAutoSellerStoreConfigErrorCategory;
import com.erp.auto.service.ErpAutoSellerStoreConfigErrorCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 自动化店铺配置
 *
 * @author WXX
 * @date 2023-12-27 19:22:13
 */
@RestController
@AllArgsConstructor
@RequestMapping("/kjerp/erpAutoSellerStoreConfigErrorCategory" )
public class ErpAutoSellerStoreConfigErrorCategoryController {

    private final ErpAutoSellerStoreConfigErrorCategoryService erpAutoSellerStoreConfigErrorCategoryService;

    //重新分组
    @GetMapping("/createGroupAgain")
    public R<Object> createGroupAgain() {
       return erpAutoSellerStoreConfigErrorCategoryService.createGroupAgain();
    }

    //查看拥有的分类


    //根据目前已经有的商品类目，给店铺标记
    @GetMapping("/jobSignStore")
    public R<Object> jobSignStore(Long storeId) {
        return erpAutoSellerStoreConfigErrorCategoryService.jobSignStore(storeId);
    }

    @GetMapping("/deleteById")
    public R<Void> deleteById(@Param("id") String id) {
        if (id.length() != 0) {
            List<String> ids = Arrays.stream(id.split(",")).collect(Collectors.toList());
            for (String idL : ids) {
                erpAutoSellerStoreConfigErrorCategoryService.deleteById(Long.valueOf(idL));
            }
        }
        return R.ok();
    }

    @GetMapping("/selectList")
    public R<Object> selectList(@RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize,
                                ErpAutoSellerStoreConfigErrorCategory category) {
        PageHelper.startPage(pageNum, pageSize);
        List<ErpAutoSellerStoreConfigErrorCategory> list = erpAutoSellerStoreConfigErrorCategoryService.selectList(category);

        PageInfo<ErpAutoSellerStoreConfigErrorCategory> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }
}
